import 'package:permission_handler/permission_handler.dart';

class AppPermissionService {
  /// Requests on device camera permission.
  static Future<bool> requestCameraPermissions() async {
    final status = await Permission.camera.request();

    if (status == PermissionStatus.permanentlyDenied) {
      // UserInteraction.showToast('访问相机权限已被永久禁止，请先在系统设置界面修改。');
      return false;
    } else if (status != PermissionStatus.granted) {
      // UserInteraction.showToast('请授权访问相机权限');
      return await requestCameraPermissions();
    }

    return true;
  }

  // /// Requests on device storage permission.
  // static Future<bool> requestStoragePermissions() async {
  //   final status = await Permission.storage.request();

  //   if (status == PermissionStatus.permanentlyDenied) {
  //     UserInteraction.showToast('访问内部存储权限已被永久禁止，请先在系统设置界面修改。');
  //     return false;
  //   } else if (status != PermissionStatus.granted) {
  //     UserInteraction.showToast('请授权访问内部存储权限');
  //     return await requestStoragePermissions();
  //   }

  //   return true;
  // }

  /// Requests on device locationWhenInUse permission.
  static Future<bool> requestLocationWhenInUsePermissions() async {
    final status = await Permission.locationWhenInUse.request();

    if (status == PermissionStatus.permanentlyDenied) {
      // UserInteraction.showToast('定位权限已被永久禁止，请先在系统设置界面修改。');
      return false;
    } else if (status != PermissionStatus.granted) {
      // UserInteraction.showToast('请授权定位权限');
      return await requestLocationWhenInUsePermissions();
    }

    return true;
  }
}
